﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework; 

namespace DeferredWaterDemo
{
    public partial class Core : Microsoft.Xna.Framework.Game
    {
        MouseState mMouse;
        KeyboardState mKeyboard;
        bool mIsFocused = false;
        bool[] mKeys = new bool[256];
        
        private void UpdateInput()
        {
            System.Windows.Forms.Form f = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(Core.Demo.Window.Handle);
            if (f.Focused == false)
            {
                mIsFocused = false;
                return;
            }

            mKeyboard = Keyboard.GetState();
            mMouse = Mouse.GetState();

            Keys[] keystate = mKeyboard.GetPressedKeys();
            Array.Clear(mKeys, 0, mKeys.Length);
            foreach (Keys k in keystate)
            {
                int index = (int)k;
                mKeys[index] = true;
            }

            float xDifference = mMouse.X - 200;
            float yDifference = mMouse.Y - 200;

            if (mIsFocused == false)
            {
                xDifference = 0f;
                yDifference = 0f;
            }

            mIsFocused = true;

            Camera.Yaw = Camera.Yaw - xDifference * .002f;
            Camera.Pitch = Camera.Pitch - yDifference * .002f;
            Mouse.SetPosition(200, 200);
        }
        
        public bool IsKeyDown(Keys key)
        {
            return mKeys[(int)key];
        }

        public bool LeftMouseDown
        {
            get
            {
                return mMouse.LeftButton == ButtonState.Pressed;
            }
        }
        public bool RightMouseDown
        {
            get
            {
                return mMouse.RightButton == ButtonState.Pressed;
            }
        }
 
    }
}
